<?php
// +----------------------------------------------------------------------
// | Azthink通用开发平台 [ TOMORROW IS ANOTHER DAY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2019 http://www.azthink.top All rights reserved.
// +----------------------------------------------------------------------
// | Author {__AUTHOR_DESCRIPTION__}
// +----------------------------------------------------------------------

namespace app\edu\model;

use think\Model;

/**
* {__CONTROLLER_DESCRIPTION__}模型
* @author {__AUTHOR_DESCRIPTION__}
* @createAt {__CREATE_TIME__}
*/
class {__MODEL_NAME__} extends Model {
	// 设置当前模型对应的完整数据表名称
	protected $table = '{__TABLE_NAME_VAR__}';
	
	// 自动写入时间戳
	protected $autoWriteTimestamp = true;
	
	//数据自动完成
	protected $auto 	= ['update_by'=>UID];
	protected $insert 	= ['create_by'=>UID];

	//修改器
	public function getStatusTextAttr($value, $data) {
		return get_status_html($data['status']);
	}

	//自定义方法
	public static function lists($status, $title) {
		$map = array();
		if ($status !== null && $status !== '') {
			array_push($map, ['a.status', '=', $status]);
		} else {
			array_push($map, ['a.status', '>=', 0]);
		}

		if ($title !== '' && !empty($title)) {
			array_push($map, ['a.title', 'like', '%'.$title.'%']);
		}
		return self::alias('a')->where($map)->order('a.id desc')->paginate();
	}

	public static function state($id, $status) {
		return self::where('id', $id)->update(['status' => $status]);
	}
}
